<template>
    <Layout :style="{padding: '0 6px 6px'}">
        <grid-table 
            :tablecolumns="tablecolumns" 
            :tabledata="tabledata" 
            :creatrouter="creatrouter" 
            :editrouter="editrouter"
            :title="title"
            :fullscreen="fullscreen"
            :showmodal="showmodal"
            :keyword="keyword"
            :routeroot="routeroot"
            :modalname="modalname"
            :vuexnamespace="vuexnamespace"
            :query="QueryResult"
            :dataoption = "false"
            :advancequery = "false"
            :deletesingle="DeleteProjectSingle"
            :deletelist="DeleteProjectList"
            :isSummary="false"
            :pageIndex="pageIndex"
            :pageSize="pageSize"/>
        
        <Footer :style="{ background: 'white',padding: '15px 10px 10px',borderRadius: '10px'}">
            <Page 
                :style="{ textAlign:'right',marginTop: '0px',paddingRight: '0px',background: 'white'}"
                show-sizer 
                show-elevator 
                show-total 
                :total="total"
                :page-size="pageSize"
                :page-size-opts="pageSizeOpts"
                @on-change="ChangePage"
                @on-page-size-change="ChangePageSize"/>
        </Footer>
    </Layout>
</template>
<script>
import { DeleteSingle,DeleteList } from '@/axios/api/ProjectAPI'
import GridTable from '@/components/GridTable/index'
import { mapState } from "vuex";

export default {
    name: 'Project',
    components: { GridTable },
    computed: {
        ...mapState('project',[
            'tablecolumns',
            'tabledata',
            'creatrouter',
            'editrouter',
            'title',
            'fullscreen',
            'showmodal',
            'total',
            'pageIndex',
            'pageSize',
            'pageSizeOpts'
        ])
    },
    created: function(){
        this.$store.dispatch('project/InitProject',{
            CreatRouter: 'Project/Project-Sheet',
            EditRouter: 'Project/Project-Sheet',
            PageIndex: this.pageIndex,
            PageSize: this.pageSize,
            Keyword: this.keyword
        })
    },
    methods: {
        ChangePage(pageIndex){
            //console.log(pageIndex)
            this.$store.dispatch('project/ChangePageIndex',{
                PageIndex: pageIndex,
                PageSize: this.pageSize,
                Keyword: this.keyword
            })
        },
        ChangePageSize(pageSize){
            this.$store.dispatch('project/ChangePageSize',{
                PageIndex: this.pageIndex,
                PageSize: pageSize,
                Keyword: this.keyword
            })
        },
        DeleteProjectSingle(selectedRow){
            if(selectedRow){
                DeleteSingle(selectedRow).then(res => {
                    if(res > 0){
                        this.$Notice.success({
                            title: '操作成功',
                            desc: '删除成功！ '
                        });

                        this.$store.dispatch('project/UpdateTableAsync',{
                            PageIndex: this.pageIndex,
                            PageSize: this.pageSize,
                            Keyword: this.keyword
                        });
                    }
                    else{
                        this.$Notice.error({
                            title: '操作失败',
                            desc: '删除失败！ '
                        });
                    }
                }).catch(err =>{
                    this.$Notice.error({
                        title: '操作提示',
                        desc: '删除失败：' + err.data + '!'
                    });
                })
            }
        },
        DeleteProjectList(selectedRows){
            //console.log('>>>>>>>>>>>>>>>DeleteList',selectedRows)
            if(selectedRows){
                DeleteList(selectedRows).then(res => {
                    if(res > 0){
                        this.$Notice.success({
                            title: '操作成功',
                            desc: '批量删除成功！ '
                        });

                        this.$store.dispatch('project/UpdateTableAsync',{
                            PageIndex: this.pageIndex,
                            PageSize: this.pageSize,
                            Keyword: this.keyword
                        });
                    }
                    else{
                        this.$Notice.error({
                            title: '操作失败',
                            desc: '批量删除失败！ '
                        });
                    }
                }).catch(err =>{
                    this.$Notice.error({
                        title: '操作提示',
                        desc: '批量删除失败！' + err.data + '!'
                    });
                })
            }
        },
        QueryResult(keyword){
            this.keyword = keyword
            this.$store.dispatch('project/UpdateTableAsync',{
                PageIndex: this.pageIndex,
                PageSize: this.pageSize,
                Keyword: keyword
            });
        }
    },
    data() {
        return {
            vuexnamespace:'project',
            modalname: "Project",
            routeroot: 'funds',
            keyword: ''
        }
    }
}
</script>
<style scoped>

</style>